<template>
	<view>
		<view>语言</view>
		<view @click="switchLanguage('zh-Hans')">中文</view>
		<view @click="switchLanguage('en')">English</view>
		<view @click="switchLanguage('es')">español</view>
	</view>
</template>

<script setup>
	import {getLang} from '@/locale/index';
	import { useI18n } from 'vue-i18n';
	import {
		ref,
		onMounted,
		getCurrentInstance
	} from "vue";
	let isAndroid = ref(false)
	const { t } = useI18n();
	
	onMounted(() => {
		let systemInfo = uni.getSystemInfoSync();
		//判断当前用户机型是否为安卓坏境
		isAndroid = systemInfo.platform.toLowerCase() === 'android';
	})

	/**
	 * @method
	 * @param {Type} 语言类型
	 * @desc 根据用户选择切换系统语言
	 */
	function switchLanguage(type) {
		if (isAndroid) {
			uni.showModal({
				content: t('login.language-change-confirm'),
				success: (res) => {
					if (res.confirm) {
						getLang(type)
					}
				}
			})
		} else {
			getLang(type)
		}
	}
</script>

<style>

</style>
